package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.EmployeeView;

public class EmployeeViewPresenter extends AbstractPresenter<EmployeeView> {
	final String SINGLEITEM = "employeeView";
	final String MULTIITEM = "employeeViews";
	
	public ArrayList<EmployeeView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public EmployeeView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public EmployeeView createItemFromJSONObject(JSONObject jsonObject){
		EmployeeView employee = new EmployeeView();
		try{
			employee.setAxed(jsonObject.getBoolean("empAxed"));
			employee.setFirstName(jsonObject.getString("empFirstName"));
			employee.setLastName(jsonObject.getString("empLastName"));
			employee.setPassword(jsonObject.getString("userPass"));
			employee.setUserName(jsonObject.getString("userName"));
			employee.setId(jsonObject.getInt("empID"));
			employee.setAxed(jsonObject.getBoolean("BBrewingAccess"));
			return employee;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(EmployeeView item){
		try{
			JSONObject json = new JSONObject();
			json.put("empAxed", item.isAxed());
			json.put("empFirstName", item.getFirstName());
			json.put("empID", item.getId());
			json.put("empLastName", item.getLastName());
			json.put("userName", item.getUserName());
			json.put("userPass", item.getPassword());
			json.put("BBrewingAccess", item.isBrewer());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public EmployeeView getEmptyEntity(){
		EmployeeView entity = new EmployeeView();
		return entity;
	}
}
